clear
set more off 
set matsize 11000
set maxvar 10000
cap log close


cd "Replication data and files\"	


use "Replication data main specifications", clear

gen poststd_9798=0
replace poststd_9798=ntr_gap_std if year== 1997 | year==1998
gen poststd_0001=0
replace poststd_0001=ntr_gap_std if year==2000 | year==2001 | year==1999
gen poststd_0203=0
replace poststd_0203=ntr_gap_std if year==2002 | year==2003
gen poststd_0405=0
replace poststd_0405=ntr_gap_std if year==2004 | year==2005
gen poststd_0607=0
replace poststd_0607=ntr_gap_std if year==2006 | year==2007
gen poststd_0809=0
replace poststd_0809=ntr_gap_std if year==2008 | year==2009
gen poststd_1011=0
replace poststd_1011=ntr_gap_std if year==2010 | year==2011
gen poststd_1213=0
replace poststd_1213=ntr_gap_std if year>=2012



drop poststdint

drop if year>2013

xtile mfaquant=mfa_county, nq(10)
qui tab mfaquant, gen(mfaquantfixed)

global mainspec poststd_* int_* provinceyearfixed* countyfixed* [aw=total_emp_c_90], cl(countycode) partial(countyfixed* int_* provinceyearfixed*)


qui ivreg2 log_gdp $mainspec
gen coeff_gdpsim_9798=_b[poststd_9798]
gen llim_gdpsim_9798 = _b[poststd_9798]-1.64*_se[poststd_9798]
gen ulim_gdpsim_9798 = _b[poststd_9798]+1.64*_se[poststd_9798]

gen coeff_gdpsim_0001=_b[poststd_0001]
gen llim_gdpsim_0001 = _b[poststd_0001]-1.64*_se[poststd_0001]
gen ulim_gdpsim_0001 = _b[poststd_0001]+1.64*_se[poststd_0001]

gen coeff_gdpsim_0203=_b[poststd_0203]
gen llim_gdpsim_0203 = _b[poststd_0203]-1.64*_se[poststd_0203]
gen ulim_gdpsim_0203 = _b[poststd_0203]+1.64*_se[poststd_0203]

gen coeff_gdpsim_0405=_b[poststd_0405]
gen llim_gdpsim_0405 = _b[poststd_0405]-1.64*_se[poststd_0405]
gen ulim_gdpsim_0405 = _b[poststd_0405]+1.64*_se[poststd_0405]

gen coeff_gdpsim_0607=_b[poststd_0607]
gen llim_gdpsim_0607 = _b[poststd_0607]-1.64*_se[poststd_0607]
gen ulim_gdpsim_0607 = _b[poststd_0607]+1.64*_se[poststd_0607]

gen coeff_gdpsim_0809=_b[poststd_0809]
gen llim_gdpsim_0809 = _b[poststd_0809]-1.64*_se[poststd_0809]
gen ulim_gdpsim_0809 = _b[poststd_0809]+1.64*_se[poststd_0809]

gen coeff_gdpsim_1011=_b[poststd_1011]
gen llim_gdpsim_1011 = _b[poststd_1011]-1.64*_se[poststd_1011]
gen ulim_gdpsim_1011 = _b[poststd_1011]+1.64*_se[poststd_1011]

gen coeff_gdpsim_1213=_b[poststd_1213]
gen llim_gdpsim_1213 = _b[poststd_1213]-1.64*_se[poststd_1213]
gen ulim_gdpsim_1213 = _b[poststd_1213]+1.64*_se[poststd_1213]




********************************************



global mainspec poststd_* int_* provinceyearfixed* countyfixed* license_std tariff_std  veryhighpost ntr_rate_std soefixed* mfaquantfixed*  [aw=total_emp_c_90], cl(countycode) partial(countyfixed* int_* provinceyearfixed*)

qui ivreg2 log_gdp $mainspec
gen coeff_gdp_9798=_b[poststd_9798]
gen llim_gdp_9798 = _b[poststd_9798]-1.64*_se[poststd_9798]
gen ulim_gdp_9798 = _b[poststd_9798]+1.64*_se[poststd_9798]

gen coeff_gdp_0001=_b[poststd_0001]
gen llim_gdp_0001 = _b[poststd_0001]-1.64*_se[poststd_0001]
gen ulim_gdp_0001 = _b[poststd_0001]+1.64*_se[poststd_0001]

gen coeff_gdp_0203=_b[poststd_0203]
gen llim_gdp_0203 = _b[poststd_0203]-1.64*_se[poststd_0203]
gen ulim_gdp_0203 = _b[poststd_0203]+1.64*_se[poststd_0203]

gen coeff_gdp_0405=_b[poststd_0405]
gen llim_gdp_0405 = _b[poststd_0405]-1.64*_se[poststd_0405]
gen ulim_gdp_0405 = _b[poststd_0405]+1.64*_se[poststd_0405]

gen coeff_gdp_0607=_b[poststd_0607]
gen llim_gdp_0607 = _b[poststd_0607]-1.64*_se[poststd_0607]
gen ulim_gdp_0607 = _b[poststd_0607]+1.64*_se[poststd_0607]

gen coeff_gdp_0809=_b[poststd_0809]
gen llim_gdp_0809 = _b[poststd_0809]-1.64*_se[poststd_0809]
gen ulim_gdp_0809 = _b[poststd_0809]+1.64*_se[poststd_0809]

gen coeff_gdp_1011=_b[poststd_1011]
gen llim_gdp_1011 = _b[poststd_1011]-1.64*_se[poststd_1011]
gen ulim_gdp_1011 = _b[poststd_1011]+1.64*_se[poststd_1011]

gen coeff_gdp_1213=_b[poststd_1213]
gen llim_gdp_1213 = _b[poststd_1213]-1.64*_se[poststd_1213]
gen ulim_gdp_1213 = _b[poststd_1213]+1.64*_se[poststd_1213]




keep in 1
gen index=1

keep ulim_* llim_* coeff_* index

rename *_0001 *_1
rename *_0203 *_203
rename *_0405 *_405
rename *_0607 *_607
rename *_0809 *_809


reshape long ulim_gdp_ llim_gdp_ coeff_gdp_  ulim_gdpsim_ llim_gdpsim_ coeff_gdpsim_, i(index) j(year)

replace year=1997 if year==9798
replace year=1999 if year==1
replace year=2002 if year==203
replace year=2004 if year==405
replace year=2006 if year==607
replace year=2008 if year==809
replace year=2010 if year==1011
replace year=2012 if year==1213

foreach x in gdp gdpsim {
lab var coeff_`x'_ "Coefficient"
lab var ulim_`x'_ "Upper bound"
lab var llim_`x'_ "Lower bound"
}
lab var year "Year"


sort year





graph twoway (rarea ulim_gdp_ llim_gdp_ year, fcolor(gs12) lstyle(thin) lcolor(black)) (line coeff_gdp_ year, lcolor(black) lpattern(dash)) , xlabel(1997(2)2013) legend(rows(2) label(1 "Confidence interval") label(2 "Coefficient")) ylabel(, grid glcolor(gs12) glwidth(vthin))
graph export "GDPannual.png", replace


graph twoway (rarea ulim_gdpsim_ llim_gdpsim_ year, fcolor(gs12) lstyle(thin) lcolor(black)) (line coeff_gdpsim_ year, lcolor(black) lpattern(dash)) , xlabel(1997(2)2013) legend(rows(2) label(1 "Confidence interval") label(2 "Coefficient")) ylabel(, grid glcolor(gs12) glwidth(vthin))
graph export "GDPannualsim.png", replace
